package com.ljkj.blockpay.ui.activity;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import android.os.Bundle;
import android.view.View;

import com.ljkj.blockpay.R;
import com.ljkj.blockpay.basedata.BaseActivity;
import com.ljkj.blockpay.databinding.ActivityLoginBinding;
import com.ljkj.blockpay.presenter.LoginPresenter;
import com.ljkj.blockpay.ui.fragment.EmailLoginFragment;
import com.ljkj.blockpay.ui.fragment.PhoneLoginFragment;
import com.ljkj.blockpay.util.ToggleToActivity;
import com.ljkj.blockpay.widget.ClickListener;

import java.util.ArrayList;

public class LoginActivity extends BaseActivity<ActivityLoginBinding,LoginPresenter> implements ClickListener {

    private ArrayList<Fragment> fragments;
    private final String[] tabs = new String[]{"手机", "邮箱"};


    @Override
    public int initContentView() {
        return R.layout.activity_login;
    }

    @Override
    protected LoginPresenter createPresenter() {
        return null;
    }

    @Override
    protected void init(Bundle savedInstanceState) {

    }

    @Override
    protected void initData() {
        super.initData();
        binding.tvTitle.setLeftBackFinish(this);
        fragments = new ArrayList<>();
        fragments.add(new PhoneLoginFragment());
        fragments.add(new EmailLoginFragment());
        binding.vpTab.setAdapter(new MypagerAdapter(getSupportFragmentManager()));
        binding.commonTablayout.setViewPager(binding.vpTab,tabs);
    }

    @Override
    public void onClick(View view) {

        switch (view.getId()){
            case R.id.tv_title:
                ToggleToActivity.toMainActivity(this);
                break;


        }
    }

    private class MypagerAdapter extends FragmentPagerAdapter{

        public MypagerAdapter(FragmentManager fm){
            super(fm);

        }

        @Override
        public int getCount() {
            return fragments.size();
        }

        @Nullable
        @Override
        public CharSequence getPageTitle(int position) {
            return tabs[position];
        }

        @NonNull
        @Override
        public Fragment getItem(int position) {
            return fragments.get(position);
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

    }

}